﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace SQLTouch.Service.DataContracts
{
    [DataContract]
    public class OrderByData : IEquatable<OrderByData>
    {
        [DataMember]
        private readonly string column;
        [DataMember]
        private readonly bool isAscending;

        private OrderByData()
        {

        }

        public OrderByData(string column, bool isAscending)
        {
            this.column = column;
            this.isAscending = isAscending;
        }

        public string Column
        {
            get { return column ?? string.Empty; }
        }

        public bool IsAscending
        {
            get { return isAscending; }
        }

        public bool Equals(OrderByData other)
        {
            return this.Column == other.Column && this.IsAscending == other.IsAscending;
        }

        public override int GetHashCode()
        {
            return this.Column.GetHashCode() ^ this.IsAscending.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            if (obj is OrderByData)
            {
                return Equals((OrderByData)obj);
            }
            else
            {
                return false;
            }
        }

        public static bool operator ==(OrderByData left, OrderByData right)
        {
            return left.Equals(right);
        }

        public static bool operator !=(OrderByData left, OrderByData right)
        {
            return !(left == right);
        }
    }
}
